# coding:utf-8

import functools
from django.shortcuts import redirect, reverse
from app.models import ClientUser
# 装饰器：确保所有页面都是用户登陆以后才能访问


def dashboard_auth(func):

    @functools.wraps(func)
    def wrapper(self, request, *args, **kwargs):

        user = request.user

        if not user.is_authenticated:
            return redirect('{}?to={}'.format(reverse('login'), request.path))

        return func(self, request, *args, **kwargs)
    return wrapper
